﻿using System;

namespace DelegateAcessors
{
    internal class Program
    {


        private static void Main(string[] args)
        {
            TestDelegateAccessors testDelegateAccessors = new TestDelegateAccessors();
            testDelegateAccessors.PriceChanged += TestDelegateAccessors_PriceChanged;
            testDelegateAccessors.TestAccessors();
            ClassDealEvent classDealEvent = new ClassDealEvent();
            classDealEvent.interfaceFistEvent += ClassDealEvent_interfaceFistEvent;
            classDealEvent.DealFistEventBusiness();

        }

        private static void ClassDealEvent_interfaceFistEvent(object sender, EventArgs e)
        {
            Console.WriteLine("接口当中的事件也被触发了");
        }

        private static void TestDelegateAccessors_PriceChanged(object sender, EventArgs e)
        {
            Console.WriteLine("我执行了");
        }

       
        
    }

    internal class TestDelegateAccessors
    {
        private EventHandler priceChanged;

        public event EventHandler PriceChanged
        {
            add { priceChanged += value; }
            remove { priceChanged -= value; }
        }

        public void TestAccessors()
        {
            priceChanged?.Invoke(this, null);
        }
    }

    public interface InterfaceWithEvent
    {
        event EventHandler interfaceFistEvent;

        void DealFistEventBusiness();
     
    }

    public class ClassDealEvent : InterfaceWithEvent
    {
        public event EventHandler interfaceFistEvent;

        public void DealFistEventBusiness()
        {
            interfaceFistEvent?.Invoke(this, null);
        }
    }
}